package com.mxpio.erp.common.inventory.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.technology.entity.ItemGroup;
import com.mxpioframework.jpa.annotation.DictAble;
import com.mxpioframework.jpa.annotation.Generator;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.Dept;
import com.mxpioframework.security.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "v_mb_erp_inv_flow")
@NoArgsConstructor
@AllArgsConstructor
@Schema(description="库存流水视图")//原InvFlow无物资组字段，无法根据该字段过滤，故增加此视图
public class VInvFlow implements DictAble, Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "ID_", updatable = false)
	@Generator
	@Schema(description = "流水号")
	private String id;

	@Column(name = "CREATE_BY", updatable = false)
	@Schema(description = "创建人")
	@Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
	private String createBy;

	@Column(name = "CREATE_DEPT", updatable = false)
	@Schema(description = "创建部门")
	@Dict(dicCode = "deptCode", dicEntity = Dept.class, dicText = "deptName")
	private String createDept;

	@Column(name = "UPDATE_BY")
	@Schema(description = "更新人")
	@Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
	private String updateBy;

	@Column(name = "CREATE_TIME", updatable = false)
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@Schema(description = "创建时间")
	private Date createTime;

	@Column(name = "UPDATE_TIME")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@Schema(description = "更新时间")
	private Date updateTime;

	@Column(name = "ACCESS_TYPE_")
	@Schema(description = "出入类型")
	@Dict(dicCode = "ERP_INV_ACCESS_TYPE")
	private String accessType;
	
	@Column(name = "ITEM_CODE_")
	@Schema(description = "物料代码")
	private String itemCode;
	
	@Column(name = "QUANTITY_")
	@Schema(description = "数量")
	private BigDecimal quantity;
	
	@Column(name = "LOT_NO_")
	@Schema(description = "批次号")
	private String lotNo;

	@Column(name = "SUB_LOT_INDEX_")
	@Schema(description = "子批次索引号")//无子批默认为0
	private String subLotIndex;
	
	@Column(name = "ORIGIN_BIZ_NO_")
	@Schema(description = "来源单号")
	private String originBizNo;
	
	@Column(name = "ORIGIN_BIZ_TYPE_")
	@Schema(description = "来源单据类型")
	private String originBizType;
	
	@Column(name = "ORIGIN_BIZ_LINE_NO_")
	@Schema(description = "来源单行号")
	private String originBizLineNo;
	
	@Column(name = "WO_BIZ_NO_")
	@Schema(description = "仓单单号")
	private String woBizNo;
	
	@Column(name = "WO_BIZ_LINE_NO_")
	@Schema(description = "仓单行号")
	private String woBizLineNo;
	
	@Column(name = "WO_BIZ_TYPE_")
	@Schema(description = "仓单类型")
	@Dict(dicCode = "ERP_INV_WO_TYPE")
	private String woBizType;
	
	@Column(name = "WH_CODE_")
	@Schema(description = "仓库编号")
	@Dict(dicCode = "whCode" ,dicEntity = Warehouse.class, dicText = "whName")
	private String whCode;
	
	@Column(name = "MEMO_")
	@Schema(description = "备注")
	private String memo;

	@Column(name = "ITEM_NAME_")
	@Schema(description = "物料名称")
	private String itemName;

	@Column(name = "ITEM_GROUP_CODE_")
	@Schema(description = "物料组")
	@Dict(dicCode="groupCode", dicEntity = ItemGroup.class, dicText = "groupName")
	private String itemGroupCode;

	@Column(name = "ITEM_SPEC_")
	@Schema(description = "物料规格")
	private String itemSpec;

	@Column(name = "UNIT_CODE_")
	@Schema(description = "单位编号")
	@Dict(dicCode="ERP_TECH_UNIT_CODE")
	private String unitCode;

	@Column(name = "DRAWING_NO_")
	@Schema(description = "图号")
	private String drawingNo;

	@Column(name = "INSPECTOR_")
	@Schema(description = "检验人")
	@Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
	private String inspector;

	@Column(name = "INSPECTION_FINISH_TIME_")
	@Schema(description = "检验结束时间")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date inspectionFinishTime;
	@Transient
	private Map<String, String> textMap;

	public String putText(String key, String value) {
		if (textMap == null) {
			textMap = new HashMap<>();
		}
		return textMap.put(key, value);
	}
}
